import pandas as pd
import requests
import json
# 读取 Excel 文件并指定 sheet 页
#excel_file_path = 'D:\Downloads\ChromeDownload\自动审核-素材明细.xlsx'  # 替换为你的 Excel 文件路径
excel_file_path = r'C:\Users\luowenjie\Desktop\影片补全\数生-电影.xlsx'
sheet_name = 'Sheet2'  # 替换为你的 sheet 页名称

# 使用 pandas 读取 Excel 文件
df = pd.read_excel(excel_file_path, sheet_name=sheet_name)
# 基础 URL
base_url = "http://106.55.8.90:7001/api/syncCompletion/syncCompletion/invoke?coocaaVId={}"
# 读取数据
# 初始化计数器
success_count = 0
failure_count = 0

for idx, row in df.iterrows():
    mediaId = row['ID']

    # 1. 检查 mediaId 是否是有效字符串（跳过 None/NaN/非字符串）
    if not isinstance(mediaId, str):
        print(f"Skipping invalid mediaId (not str): {mediaId} (type: {type(mediaId)})")
        failure_count += 1
        continue

    # 2. 检查是否以 "do" 开头
    if not mediaId.startswith("do"):
        url = base_url.format(mediaId)
        try:
            # 3. 发送请求
            response = requests.get(url, timeout=10)  # 建议加 timeout
            response.raise_for_status()  # 如果状态码不是 200，抛出异常

            # 4. 请求成功，处理响应
            print(f"Success for {mediaId}: {response.text[:100]}...")  # 打印前100字符避免冗长
            success_count += 1

        except requests.exceptions.RequestException as e:
            # 5. 请求失败，记录错误
            print(f"Error occurred for {mediaId}: {e}")
            failure_count += 1
    else:
        print(f"Skipping {mediaId} (starts with 'do')")

# 6. 打印最终统计
print("\n===== Summary =====")
print(f"Total requests: {len(df)}")
print(f"Success: {success_count}")
print(f"Failures: {failure_count}")
print(f"Skipped (invalid or 'do' prefix): {len(df) - success_count - failure_count}")